<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('market');

$condition = array();
/*代理商数据*/
$conditions = array( 'city_id'=>$login_user[city_id]);


$income_state = abs(intval($_GET['income_state']));
if($income_state) {
$t_con = array( 'state' => $income_state );
$partnerincomes = DB::LimitQuery('partnerincome', array('condition'=>$t_con));
$t_id = Utility::GetColumn($partnerincomes, 'partner_id');
	if ($t_id) { 
		$condition['id'] = $t_id;
	} else {
		$condition['id'] = 0;
	}
}
/* filter */
$ptitle = strval($_GET['ptitle']);
if ($ptitle ) {
	$condition[] = "title LIKE '%".mysql_escape_string($ptitle)."%'";
}
$group_id = strval($_GET['group_id']);
if ($group_id) {
	$condition['group_id'] = $group_id;
}
$city_id = strval($_GET['city_id']);
if ($group_id) {
	$condition['city_id'] = $city_id;
}
$open = strval($_GET['open']);
if ($open) {
	$condition['open'] = $open;
}
/* filter end */
/* 代理商filter */
$ptitle = strval($_GET['ptitle']);
if ($ptitle ) {
	$conditions[] = "title LIKE '%".mysql_escape_string($ptitle)."%'";
}
$group_id = strval($_GET['group_id']);
if ($group_id) {
	$conditions['group_id'] = $group_id;
}
$city_id = strval($_GET['city_id']);
if ($group_id) {
	$conditions['city_id'] = $city_id;
}
$open = strval($_GET['open']);
if ($open) {
	$conditions['open'] = $open;
}
/* filter end */

$count = Table::Count('partner', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);

$partners = DB::LimitQuery('partner', array(
	'condition' => $condition,
	'order' => 'ORDER BY head DESC, id DESC',
	'size' => $pagesize,
	'offset' => $offset,
));
$groups = option_category('partner');
$cities = option_category('city');
/*代理商数据*/
$counts = Table::Count('partner', $conditions);
list($pagesize, $offset, $pagestrings) = pagestring($counts, 20);

$partnerss = DB::LimitQuery('partner', array(
	'condition' => $conditions,
	'order' => 'ORDER BY head DESC, id DESC',
	'size' => $pagesize,
	'offset' => $offset,
));

include template('manage_partner_index');
